package com.example.springai.function;

import com.fasterxml.jackson.annotation.JsonClassDescription;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

public class MockWeatherService implements Function<MockWeatherService.Request, MockWeatherService.Response> {

	public enum Unit { C, F }
	@JsonClassDescription("查看当地天气温度 , 温度单位为摄氏度或华氏度 ,地区为中文")
	public record Request(List<String> locations, Unit unit) {}

	public record Response(
			Map<String, Double> temperatures,
			Unit unit
	) {}

	public Response apply(Request request) {
		System.out.println("request = " + request);
		Map<String, Double> temps = new HashMap<>();
		for (String location : request.locations) {
			System.out.println("location = " + location);
			temps.put(location, getMockTemperature(location));
		}
		return new Response(temps, request.unit);
	}
	private double getMockTemperature(String location) {
		// Return a mock temperature based on the location
		if ("西安".equals(location)) {
			return 15.0;
		} else if ("北京".equals(location)) {
			return 20.0;
		} else if ("上海".equals(location)) {
			return 18.0;
		} else {
			return 0.0;
		}
	}

}
